package com.zjitc.chapter12.controller;

import com.zjitc.chapter12.domain.User;
import com.zjitc.chapter12.domain.dto.UserDto;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;

@Controller
public class UserController {
    @RequestMapping("/getUserById")
    public void getUserById(HttpServletRequest request) {
        System.out.println("UserController.getUserById");
        System.out.println("userId = " + request.getParameter("userId"));
    }
    @RequestMapping("/getUserByName")
    public void getUserByName(String name) {
        System.out.println("UserController.getUserByName");
        System.out.println("name = " + name);
    }
    @RequestMapping("/getUserByAge")
    public void getUserByAge(@RequestParam(value = "age",defaultValue = "12") int age) {
        System.out.println("UserController.getUserByAge");
        System.out.println("age = " + age);
    }
    @RequestMapping("/getPathVariable/{id}")
    public void getPathVariable(@PathVariable(value = "id") int id) {
        System.out.println("UserController.getPathVariable");
        System.out.println("id = " + id);
    }
    @RequestMapping("/register")
    public String  register(String username,String password) {
        return "register";
    }
    @RequestMapping("/registerUser")
    public void registerUser(UserDto userDto) {
        System.out.println("UserController.register");
        System.out.println("userDto = " + userDto);
    }
    @RequestMapping("/getBirthday")
    public void getBirthday(@DateTimeFormat(pattern = "yyyy-MM-dd") Date birthday) {
        System.out.println("UserController.getBirthday");
        System.out.println("birthday = " + birthday);
    }
    @RequestMapping("/findOrderWithUser")
    public void findOrderWithUser(User user) {
        System.out.println("UserController.findOrderWithUser");
        System.out.println("user = " + user);
    }
}
